package com.zretc.support.controller;


import com.zretc.support.entity.Log;
import com.zretc.support.service.LogService;
import com.zretc.support.tool.AjaxResponse;
import com.zretc.support.tool.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("api")
public class LogController {
    @Autowired
    LogService logService;

    /**
     * 添加日志，ok
     * @param log
     * @return
     */
    @PostMapping(value = "addlog",produces = "application/json;charset=utf-8")
    AjaxResponse addLog(@RequestBody Log log){
        return logService.addLog(log);
    }

    /**
     * 模糊查询对象，有分页,ok
     * @param username  用户姓名
     * @param page    当前页码
     * @param limit  每页输出的条数
     * @return  返回值是日志列表
     */
    @GetMapping(value = "getlog")
    @ResponseBody
    public PageData<Log> getlike(@RequestParam(value = "username",defaultValue = "") String username,
                                 @RequestParam(value = "page",defaultValue = "1") int page,
                                 @RequestParam(value = "limit",defaultValue = "10") int limit){

        return logService.findLogByLike(username,(page-1),limit);
    }

    @GetMapping(value = "getloginfo")
    @ResponseBody
    public PageData<Log> getlog( @RequestParam(value = "username",defaultValue = "") String username,
                                 @RequestParam(value = "startDate") String startDate,
                                 @RequestParam(value = "endDate") String endDate,
                                 @RequestParam(value = "page",defaultValue = "1") int page,
                                 @RequestParam(value = "limit",defaultValue = "10") int limit){

        return logService.findLogByDate(username,startDate,endDate,(page-1),limit);
    }
}
